package com.ruoyi.web.controller.warehouseManagement;


import java.util.List;
import javax.servlet.http.HttpServletResponse;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.ProductStockOut;
import com.ruoyi.system.service.IProductStockOutService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 商品出库 Controller
 *
 * @author ruoyi
 * @date 2025-05-30
 */
@Api(tags="商品出库")
@RestController
@RequestMapping("/system/productStockOut")
public class ProductStockOutController extends BaseController
{
    @Autowired
    private IProductStockOutService productStockOutService;

    /**
     * 查询商品出库列表
     */
    @ApiOperation("查询商品出库列表")
    @PreAuthorize("@ss.hasPermi('system:out:list')")
    @GetMapping("/list")
    public TableDataInfo list(@RequestParam (required = false) String warehouseName)
    {
        startPage();
        List<ProductStockOut> list = productStockOutService.selectProductStockOutListByName(warehouseName);
        return getDataTable(list);
    }

    /**
     * 导出商品出库列表
     */
    @ApiOperation("导出商品出库列表")
    @PreAuthorize("@ss.hasPermi('system:out:export')")
    @Log(title = "商品出库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, @RequestParam (required = false) String warehouseName)
    {
        List<ProductStockOut> list = productStockOutService.selectProductStockOutListByName(warehouseName);
        ExcelUtil<ProductStockOut> util = new ExcelUtil<ProductStockOut>(ProductStockOut.class);
        util.exportExcel(response, list, "商品出库数据");
    }

    /**
     * 通过id获取商品出库详细信息
     */
    @ApiOperation("通过id获取商品出库详细信息")
    @PreAuthorize("@ss.hasPermi('system:out:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(productStockOutService.selectProductStockOutById(id));
    }

    /**
     * 新增商品出库
     */
    @ApiOperation("新增商品出库")
    @PreAuthorize("@ss.hasPermi('system:out:add')")
    @Log(title = "商品出库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ProductStockOut productStockOut)
    {
        return toAjax(productStockOutService.insertProductStockOut(productStockOut));
    }

    /**
     * 修改商品出库
     */
    @ApiOperation("修改商品出库")
    @PreAuthorize("@ss.hasPermi('system:out:edit')")
    @Log(title = "商品出库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ProductStockOut productStockOut)
    {
        return toAjax(productStockOutService.updateProductStockOut(productStockOut));
    }

    /**
     * 通过id批量删除商品出库信息
     */
    @ApiOperation("通过id批量删除商品出库信息")
    @PreAuthorize("@ss.hasPermi('system:out:remove')")
    @Log(title = "商品出库", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(productStockOutService.deleteProductStockOutByIds(ids));
    }
}
